#include "pch.h"
#include "LightBase.h"

using namespace DirectX;

LightBase::LightBase(void) :
	m_lightColorAndFalloff(1.0f, 1.0f, 1.0f, 1.0f),
	m_lightParametersBuffer(),
	m_lightBaseUpdateRequired(true),
	m_pixelShader()
{
}

void LightBase::LightColor(float r, float g, float b)
{
	m_lightColorAndFalloff = XMFLOAT4(r, g, b, m_lightColorAndFalloff.w);
	m_lightBaseUpdateRequired = true;
}

DirectX::XMFLOAT3 LightBase::LightColor(void)
{
	return XMFLOAT3(m_lightColorAndFalloff.x, m_lightColorAndFalloff.y, m_lightColorAndFalloff.z);
}

void LightBase::Falloff(float falloff)
{
	m_lightColorAndFalloff.w = falloff;
	m_lightBaseUpdateRequired = true;
}

float LightBase::Falloff(void)
{
	return m_lightColorAndFalloff.w;
}

void LightBase::SetBuffersForRendering(ID3D11DeviceContext* context)
{
	if (m_lightBaseUpdateRequired)
	{
		context->UpdateSubresource(m_lightParametersBuffer.Get(), 0, nullptr, &m_lightColorAndFalloff, 0, 0);
		m_lightBaseUpdateRequired = false;
	}
	context->PSSetConstantBuffers(1, 1, m_lightParametersBuffer.GetAddressOf());
}
